/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.audit.client  
 */
package com.apache.client;

import java.util.Map;

import com.apache.api.vo.ResultEntity;
import com.apache.attachment.mommon.ToolsUtil;
import com.apache.method.ThreadPool;
import com.apache.rpc.client.RpcProtoclClient;
import com.apache.rpc.entity.InterfaceRegister;

/**
 * description:  客户端直接写日志
 * @author dwusoft 创建时间：2015-4-13  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class LogClient {

	private static LogClient instance;

	private LogClient() {
	}

	public static LogClient getInstance() {
		if (null == instance) {
			instance = new LogClient();
		}
		return instance;
	}

	/**
	 * description:  为用户登录/ 退出提供
	 * @param params 参数   modelEname：模型Ename
	 *     说明：登录（key:logOperationType = login;key:logIp = 实际IP；key:log_userEname = 操作用户）
	 *           退出（key:logOperationType = logout;key:logIp = 实际IP；key:log_userEname = 操作用户）
	 * @return  
	 */
	public ResultEntity execute(Map<String, Object> params) {
		InterfaceRegister register = new InterfaceRegister();
		register.setAddress(ToolsUtil.getInstance().getValueByKey("audit_server_url"));
		register.setCallType(ToolsUtil.getInstance().getValueByKey("audit_server_type"));
		register.setPort(ToolsUtil.getInstance().getValueByKey("audit_server_port"));
		return RpcProtoclClient.getInstance().doService("auditService", "logOperationSave", params, register);
	}

	/**
	 * description:  为用户登录/ 退出提供
	 * @param params 参数   modelEname：模型Ename
	 *     说明：登录（key:logOperationType = login;key:logIp = 实际IP；key:log_userEname = 操作用户）
	 *           退出（key:logOperationType = logout;key:logIp = 实际IP；key:log_userEname = 操作用户）
	 * @return  
	 */
	public void doInvoke(Map<String, Object> params) {
		params.put("log_returnValue", "true");
		LoggerClientRunnable runnable = new LoggerClientRunnable(null, params);
		ThreadPool.newFixedThreadPool(1).execute(runnable);
	}
}
